class NoticeView extends BaseView{

    public constructor(){
        super();
        this.addEventListener(egret.Event.ADDED_TO_STAGE,this.getViews,this);
    }

    private static noticeView:NoticeView;
    public static getInstance():NoticeView{
        if(!this.noticeView){
            this.noticeView = new NoticeView();
        }
        return this.noticeView;
    }
    private getViews(){
        let mask = new egret.Shape;
        mask.graphics.beginFill(0x000000, 0.6);
        mask.graphics.drawRect(0, 0, this.width, this.height);
        mask.graphics.endFill();
        mask.touchEnabled = true;
        this.addChild(mask);
        this.bg = utils.createBitmapByName('friend');
        this.bg.scale9Grid = new egret.Rectangle(250, 160, 100, 50);
        this.bg.width = GameData.stageW * 0.9;
        this.bg.height = 400;
        this.bg.x = GameData.stageW * 0.05;
        this.bg.y = GameData.stageH / 2 - this.bg.height / 2;
        this.addChild(this.bg);
        
        this.noticesprite = new egret.Sprite;
        this.noticesprite.width = this.width * 0.7;
        this.noticesprite.x = this.width / 2 - this.noticesprite.width / 2;
        this.noticesprite.height = this.bg.height;
        this.addChild(this.noticesprite);
        this.noticemsg = new BaseTextField;
        this.noticemsg.textColor = 0xb16f11;
        this.noticemsg.size = 36;
        this.noticemsg.bold = true;
        this.noticemsg.lineSpacing = 10;
        this.noticemsg.textAlign = 'center';
        this.noticemsg.width = this.noticesprite.width;
        this.noticemsg.y = this.bg.y + 150;
        this.noticesprite.addChild(this.noticemsg);

        this.close = utils.createBitmapByName('x');
        this.close.width = 64;
        this.close.height = 72;
        this.close.x = utils.getMaxX(this.bg) - 100;
        this.close.y = this.bg.y + 50;
        this.close.touchEnabled = true;
        this.close.addEventListener(egret.TouchEvent.TOUCH_TAP,this.closeNotice,this);
        this.addChild(this.close);

        this.title = new BaseTextField;
        this.title.text = "提  示";
        this.title.size = 40;    
        this.title.bold = true;
        this.title.textColor = 0xffec73;
        this.title.y = this.bg.y + 40;
        this.title.x = this.width / 2 - this.title.width / 2;
        this.title.stroke = 2;
        this.title.strokeColor = 0x6b400b;
        this.addChild(this.title);
    }

    private bg:egret.Bitmap;
    private noticesprite:egret.Sprite;
    private noticemsg:BaseTextField;
    private close:egret.Bitmap;

    private title:BaseTextField;
    private noticecallback:()=>void;
    public set noticeMsg(value:string){
        this.noticemsg.text = value;
        this.noticemsg.x = this.noticesprite.width / 2 - this.noticemsg.width / 2;
        this.noticemsg.y = this.bg.y + this.bg.height / 2 - this.noticemsg.height / 2 + 30;
    }
    public set noticetitle(value:string){
        this.title.text = value;
        this.title.x = this.width / 2 - this.title.width / 2;
    }

    public set callback(callback:()=>void){
        this.noticecallback = callback;
    }
    private closeNotice(){
        if(this.noticecallback){
            this.noticecallback();
        }
        this.parent.removeChild(this);
    }
}